//
//  BasePeopleViewController.m
//  TQY
//
//  Created by 甘世清 on 2024/10/16.
//

#import "BasePeopleViewController.h"
#import "PeopleListViewController.h"
#import "SQCLLocationManager.h"

@interface BasePeopleViewController ()
@property (nonatomic , strong) PeopleListViewController * newVC;
@property (nonatomic , strong) PeopleListViewController * fujinVC;
@property (nonatomic , strong) PeopleListViewController * huoyueVC;
@property (nonatomic , strong) PeopleListViewController * renzhenVC;
@end

@implementation BasePeopleViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    UIImageView * bgImageView = [[UIImageView alloc]init];
    bgImageView.image = SQGetImage(@"二级背景");
    [self.view addSubview:bgImageView];
    [bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view);
        
    }];
    [self SQ_UIViewForSelfView];
    [self.view sendSubviewToBack:bgImageView];
}

- (void)SQ_UIViewForSelfView{
    self.tabContentView.delegate = self;
    self.tabContentView.backgroundColor = UIColor.clearColor;
    self.tabBar.backgroundColor = UIColor.clearColor;
    self.tabBar.indicatorColor  = SQColor3DA59D;
    [self.tabBar setIndicatorWidth:40 marginTop:40 marginBottom:7 tapSwitchAnimated:YES];
    [self setTabBarFrame:CGRectMake(10, TopHeight-40, SCREEN_WIDETH-20,50)
        contentViewFrame:CGRectMake(0, TopHeight+10, SCREEN_WIDETH, SCREEN_HEIGHT-TopHeight-FootHeight-50)];
    self.tabBar.itemTitleFont = FONT_MEDIUM(16);
    self.tabBar.itemTitleSelectedFont = FONT_MEDIUM(20);
    self.tabBar.itemTitleColor = SQColor(@"#BCB0D9");
    self.tabBar.itemTitleSelectedColor = SQColor3DA59D;
    [self.tabBar setScrollEnabledAndItemFitTextWidthWithSpacing:20 minWidth:70];
    [self.tabContentView setContentScrollEnabled:YES tapSwitchAnimated:YES];
    self.tabContentView.loadViewOfChildContollerWhileAppear = YES;
    self.viewControllers = [[NSMutableArray alloc]initWithObjects:self.newVC,self.fujinVC,self.huoyueVC,self.renzhenVC, nil];

}
/**
 *  是否能切换到指定index
 */
- (BOOL)tabContentView:(YPTabContentView *)tabConentView shouldSelectTabAtIndex:(NSUInteger)index{
    if (index >0) {
        if ([UserModel share].isVip) {
            if ([SQCLLocationManager sharedManager].authorizationStatus != kCLAuthorizationStatusDenied ){
                return YES;
            }
            [self SQ_HeaderViewqButtonClick];
            return NO;
        } else {
            [VipPopView SQ_Show];
            return NO;
        }
    }
    return YES;
}

-(void)SQ_HeaderViewqButtonClick{
   
    UIAlertController * alert = [UIAlertController alertControllerWithTitle:SQNSLocalString(@"设置定位权限") message:@"该功能需要访问您当前定位进行筛选,请开启定位后使用" preferredStyle:UIAlertControllerStyleActionSheet];
    
    UIAlertAction * co1 = [UIAlertAction actionWithTitle:SQNSLocalString(@"去开启") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        NSURL * url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
        if ([[UIApplication sharedApplication] canOpenURL:url]) {
            [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:^(BOOL success) {
            }];
        }
    }];
    UIAlertAction * co2 = [UIAlertAction actionWithTitle:SQNSLocalString(@"取消") style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    [alert addAction:co1];
    [alert addAction:co2];
    [self presentViewController:alert animated:YES completion:nil];
}

- (PeopleListViewController *)newVC{
    if (!_newVC) {
        _newVC = [[PeopleListViewController alloc]init];
        _newVC.yp_tabItemTitle = SQNSLocalString(@"最新搭友");
        _newVC.type = @"0";
    }
    return _newVC;
}
 
- (PeopleListViewController *)fujinVC{
    if (!_fujinVC) {
        _fujinVC = [[PeopleListViewController alloc]init];
        _fujinVC.yp_tabItemTitle = SQNSLocalString(@"附近搭友");
        _fujinVC.type = @"1";
    }
    return _fujinVC;
}
- (PeopleListViewController *)huoyueVC{
    if (!_huoyueVC) {
        _huoyueVC = [[PeopleListViewController alloc]init];
        _huoyueVC.yp_tabItemTitle = SQNSLocalString(@"活跃搭友");
        _huoyueVC.type = @"2";
    }
    return _huoyueVC;
}
- (PeopleListViewController *)renzhenVC{
    if (!_renzhenVC) {
        _renzhenVC = [[PeopleListViewController alloc]init];
        _renzhenVC.yp_tabItemTitle = SQNSLocalString(@"认证搭友");
        _renzhenVC.type = @"3";
    }
    return _renzhenVC;
}
@end
